App.controller('companyIncomeAnalyzeController', ['$rootScope', '$scope', '$state', 'Page','$interval', function($rootScope, $scope, $state, Page, $interval) {


	// 查询工资单的年份
	 Page.ajaxGet('salaryPayRoll/getSalaryPayRollYear.do', null, function(resp) {
	        $scope.salaryPayRollYearList = resp.data;
	 });
	 
	 $scope.changeSalaryPayRollYear = function(){
    	 // 查询工资单年份对应的月份
    	 var param = {};
    	 param.salaryPayRollYear = $scope.payRollYear;
       	 Page.ajaxGet('salaryPayRoll/getSalaryPayRollMonthByYear.do', param, function(resp) {
       	        $scope.salaryPayRollMonthList = resp.data;
       	    });
        },

   	 $scope.highchartsObject = {
        		init : function(){
        			var chartTitle = "企业收入分析"
    				 if($scope.payRollYear == undefined){
    					 Page.notice("请选择年份");
    					 return false;
    				 }
    				 if($scope.payRollMonth == undefined){
    					 chartTitle = $scope.payRollYear+'年企业收入分析';
    				 }else {
    					 chartTitle = $scope.payRollYear+'年'+$scope.payRollMonth+'月企业收入分析';
    				 }
    				 var param = {};
    				 param.payRollYear = $scope.payRollYear;
    				 param.payRollMonth = $scope.payRollMonth;
    				 Page.ajaxGet('companyIncomeAnalyze/analyze.do', param, function(resp) {
    					 $scope.dataArray = resp.data.resultDataArray;
    					 Highcharts.chart('containerX', {
    	        			    chart: {
    	        			        plotBackgroundColor: null,
    	        			        plotBorderWidth: null,
    	        			        plotShadow: false,
    	        			        type: 'pie'
    	        			    },
    	        			    title: {
    	        			        text: chartTitle
    	        			    },
    	        			    tooltip: {
    	        			        pointFormat: '{series.name}: <b>{point.percentage:.1f}%</b>'
    	        			    },
    	        			    plotOptions: {
    	        			        pie: {
    	        			            allowPointSelect: true,
    	        			            cursor: 'pointer',
    	        			            dataLabels: {
    	        			                enabled: true,
    	        			                format: '<b>{point.name}</b>: {point.percentage:.1f} %',
    	        			                style: {
    	        			                    color: (Highcharts.theme && Highcharts.theme.contrastTextColor) || 'black'
    	        			                }
    	        			            }
    	        			        }
    	        			    },
    	        			    series: [{
    	        			        name: 'Brands',
    	        			        colorByPoint: true,
    	        			        data:  $scope.dataArray
    	        			    }]
    	        			}); 
    				 });
        		},
        		 reset : function(){
    				 $scope.payRollYear = null;
    				 $scope.payRollMonth = null;
    			 }
        }
}]);